"""用来记录浏览器与服务器之间的交互信息，由服务器设置，保存在浏览器中
设置方式：response.set_cookie(key,value,max_age)
max_age表示有效时间，单位为秒，如果不设置默认就是一次浏览器会话结束
获取方式：request.cookies.get(key)"""""

from flask import Flask
from flask import make_response
from flask import request

app = Flask(__name__)


#  装饰器路由与视图函数
@app.route('/set_cookie')
def set_cookie():
    #  获取响应体对象
    response = make_response('设置cookie')
    print(1)

    #  设置cookie
    response.set_cookie('name', 'xiaohua')
    response.set_cookie('age', '29',10)
    response.set_cookie('hobby','swim',10)

    return response


@app.route('/')
def get_cookie():
    # 1.从request中获取cookie
    name = request.cookies.get('name')
    age = request.cookies.get('age')
    hobby = request.cookies.get('hobby')

    return 'name is %s, age is %s, hobby is %s' % (name, age, hobby)


if __name__ == '__main__':
    app.run(debug=True)
